import { useTranslation } from "next-i18next";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import nextI18NextConfig from "../../next-i18next.config.js";
import { useEffect } from "react";
import { i18n } from "next-i18next";

export default () => {
  const { t } = useTranslation("common");
  useEffect(() => {
    const lang = navigator.language;
    console.log(lang, ":lang");
    if (lang == "zh-CN") {
      i18n.changeLanguage("zh", () => {
        console.log("设置中文：");
      });
    } else if (lang == "") {
      i18n.changeLanguage("en");
    }
  }, []);
  return <div>{t("welcome")}</div>;
};

export const getStaticProps = async ({ locale }) => ({
  props: {
    ...(await serverSideTranslations(locale, ["common"], nextI18NextConfig)),
  },
});
